import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
// import menus from './menu'

const routes = [
  {
    path:'/',
    redirect:{name:'Login'}
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children:[
      //首页
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/Dashboard/Dashboard.vue'),
        meta: { title: '首页', icon: 'HomeFilled', top: true }
      },
      //会员管理
      {
        path:"/memberCenter",
        name: 'MemberCenter',
        meta:{title:'会员管理',icon:'User',top:true},
        children:[
          {
            path:"member",
            name: 'Member',
            component: () => import('@/views/MemberCenter/Member.vue'),
            meta: { title: '会员', icon: 'UserFilled' }
          },
          {
            path:"memberCard",
            name: 'MemberCard',
            component: () => import('@/views/MemberCenter/MemberCard.vue'),
            meta: { title: '会员卡', icon: 'Postcard',}
          },
          {
            path:"memberBind",
            name: 'MemberBind',
            component: () => import('@/views/MemberCenter/MemberBind.vue'),
            meta: { title: '会员绑定', icon: 'Postcard',}
          }
        ]
      },
      {
        path:"/course",
        name: 'Course',
        meta:{title:'团课管理',icon:'Grid',top:true},
        children:[
          {
            path:"courseList",
            name: 'CourseList',
            component: () => import('@/views/course/CourseList.vue'),
            meta: { title: '团课课程', icon: 'List' }
          },
          {
            path:"courseSchedule",
            name: 'CourseSchedule',
            component: () => import('@/views/course/CourseSchedule.vue'),
            meta: { title: '团课课表', icon: 'Calendar' }
          },
          {
            path:"courseReservation",
            name: 'CourseReservation',
            component: () => import('@/views/course/CourseReservation.vue'),
            meta: { title: '团课预约设置', icon: 'Setting' }
          }
        ]
      },
      {
        path:"/teacher",
        name: 'Teacher',
        meta:{title:'老师管理',icon:'Avatar',top:true},
        component: () => import('@/views/teacher/TeacherList.vue'),
       
      },
      {
        path:"/statistics",
        name: 'Statistics',
        meta:{title:'数据统计',icon:'TrendCharts',top:true},
        children:[
          {
            path:"cardListStat",
            name: 'CardListStat',
            component: () => import('@/views/statistics/CardListStat.vue'),
            meta: { title: '会员卡统计', icon: 'PieChart' }
          },
          {
            path:"cardCostStat",
            name: 'CardCostStat',
            component: () => import('@/views/statistics/CardCostStat.vue'),
            meta: { title: '收费统计', icon: 'Histogram' }
          },
          {
            path:"classCostStat",
            name: 'ClassCostStat',
            component: () => import('@/views/statistics/ClassCostStat.vue'),
            meta: { title: '消课统计', icon: 'Histogram' }
          },
          {
            path:"classHourStat",
            name: 'ClassHourStat',
            component: () => import('@/views/statistics/ClassHourStat.vue'),
            meta: { title: '总课次统计', icon: 'Histogram' }
          },
          {
            path:"memberNumStat",
            name: 'MemberNumStat',
            component: () => import('@/views/statistics/MemberNumStat.vue'),
            meta: { title: '新增与流失统计', icon: 'Histogram' }
          }
        ]
      },
      // 个人中心
       {
        path:"/profile",
        name: 'Profile',
        meta:{title:'个人中心',icon:'User',},
        children:[
          {
            path:"modifyPwd",
            name: 'ModifyPwd',
            component: () => import('@/views/profile/ModifyPwd.vue'),
            meta: { title: '修改密码', icon: 'Lock' }
          },
          {
            path:"info",
            name: 'Info',
            component: () => import('@/views/profile/Info.vue'),
            meta: { title: '个人信息', icon: 'Histogram' }
          }
        ]
       } 
  
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/RegisterView.vue')
  },
  
]
//菜单栏动态路由
// 动态路由routes
/* function addRoutes(){
   menus.forEach(item=>{
    router.addRoute('home',item)
    // routes[0].children.push(item)
   })
}
addRoutes() */


// 动态路由routes
// function addRoutes(){
//    menus.forEach(item=>{
//     router.addRoute('Home',item)
//    })
// }
// addRoutes()

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局路由导航守卫
router.beforeEach((to, from, next) => {
    console.log(to,'----路由导航守卫----',from,routes)
    next()
})

export default router